package com.all.jpa.repository;

import com.all.jpa.model.entity.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author LY
 * @create 2024/4/26 15:35
 * @Description 用户mapper
 */
@Repository
public interface SysUserRepository extends JpaRepository<SysUser, Long> {
    /**
     * 非原生sql，实体类映射
     * @param userName
     * @return
     */
//    @Query("""
//        select su.userId,su.deptId,su.userName,su.nickName,su.userType,su.email,su.phonenumber from SysUser su where su.userName = ?1
//    """)

    /**
     * 原生sql
     * @param userName
     * @return
     */
    @Query(value = """
        select su.* from sys_user su where su.user_name = :userName
    """,nativeQuery = true)
    List<Map<String,Object>> findByUserName(@Param("userName") String userName);

    @Query(value = """
        select su.* from sys_user su where su.user_name = :userName
    """,nativeQuery = true)
    List<SysUser> findByUserName2(@Param("userName") String userName);

}
